﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;
namespace DAO
{
    public class TaiKhoanChinhDA
    {
        public static TaiKhoanChinh GetByID(int maID)
        {
            TaiKhoanChinh loai = null;
            SqlConnection cn = DataProvider.Connect();
            SqlCommand cmd = new SqlCommand("Proc_TaiKhoanChinh_GetById", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@maTK", maID));
            SqlDataReader dataReader = cmd.ExecuteReader();
            if (dataReader.Read())
            {
                loai = new TaiKhoanChinh();
                loai.MaTK = maID;
                loai.MaKH = Convert.ToInt32(dataReader["MaKH"]);
                loai.NgayTao = Convert.ToDateTime(dataReader["NgayTao"]);
                loai.DelFlg = Convert.ToInt32(dataReader["DelFlg"]);
                loai.KhachHang = KhachHangDA.GetById(loai.MaKH);
            }
            cn.Close();
            return loai;
        }
        public static int GetByMaKH(int maKH)
        {
            int ma = 0;
            SqlConnection cn = DataProvider.Connect();
            SqlCommand cmd = new SqlCommand("Proc_TaiKhoanChinh_GetByMaKH", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@maKH", maKH));
            SqlDataReader dataReader = cmd.ExecuteReader();
            if (dataReader.Read())
            {
                ma = Convert.ToInt32(dataReader["MaTK"]);
            }
            cn.Close();

            return ma;
        }
    }
}
